﻿@model WSCeCommerce.Domain.Sale
@using WSCeCommerce.Domain
@using WSCeCommerceWeb.Helpers
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>


@{
    ViewBag.Title = "Check out";
}

<h2 style="text-align:center">Check out</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Sale</legend>

        <h3>Items</h3>
        <br />
        <table>
            <tr style="font-size: large">
                
                <td>Item</td>
                <td>Price</td>
                <td>Quantity</td>
                <td>Total</td>
            </tr>
            @foreach (SaleItem item in Model.SaleItems)
            { 
                <tr>
                    <td>@item.Item.Name</td>
                    <td>@item.Price</td>
                    <td>@item.Quantity</td>
                    <td>@(item.Price * item.Quantity)</td>

                </tr>
            }

            <tr>
                <td><b>Total</b></td>
                <td />
                <td />
                <td><b>@Model.Total</b></td>
            </tr>
        </table>

        <h3>Shipping Address</h3>
        <br/>
        <table>
            <tr>
                <td>@Html.Label("Address (Line 1)")</td>
                <td>
                    @Html.EditorFor(model => model.ShipToAddress.AddressLine1)
                    @Html.ValidationMessageFor(model => model.ShipToAddress.AddressLine1)
                </td>
                <td></td>
            </tr>
                       
            <tr>
                <td>@Html.Label("Line 2")</td>
                <td>
                    @Html.EditorFor(model => model.ShipToAddress.AddressLine2)
                </td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.ShipToAddress.City)</td>
                <td>@Html.EditorFor(model => model.ShipToAddress.City)
                    @Html.ValidationMessageFor(model => model.ShipToAddress.City)
                </td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.ShipToAddress.Country)</td>
                <td>@Html.DropDownListFor(model => model.ShipToAddress.Country, ListHelper.GetCountries())</td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.ShipToAddress.Zip)</td>
                <td>@Html.EditorFor(model => model.ShipToAddress.Zip)
                    @Html.ValidationMessageFor(model => model.ShipToAddress.Zip)
                </td>
            </tr>
        </table>

        <h3>Payment Method</h3>
    <br/>
        @Html.DropDownListFor(model => model.CardType, ListHelper.GetCreditCardTypes())
        @Html.EditorFor(model => model.CardNumber)
        @Html.ValidationMessageFor(model => model.CardNumber)
      
            <p>
            <input type="submit" value="Submt order" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}


<script>jQuery.validator.setDefaults({ debug: true, success: "valid" });
    $("#model.cardnumber").validate({ rules: { field: { required: true, creditcard: true } } });</script>